package Presenter;

import InterFaceIModel.IThuchiModel;
import InterFaceIModel.ThuchiModel;
import View.IThuchiView;
import View.IthuchiDetailView;

public class ThuChiPresenter {

	IthuchiDetailView thuDetailView;
	IThuchiView thuchiView;
	public ThuChiPresenter(IthuchiDetailView thuDetailView)
	{
		this.thuDetailView=thuDetailView;
	}
	public long insert()
	{
		if (thuDetailView.getSotien()<0) {
			
			return -1;
		}
		IThuchiModel thuchiModel=new ThuchiModel();
		thuchiModel.setKhoanchi(thuDetailView.getKhoanchi());
		thuchiModel.setSotien(thuDetailView.getSotien());
		thuchiModel.setLoaiThuchi(thuDetailView.getLoaiThuChi());
		thuchiModel.setNgaychi(thuDetailView.getNgaychi());
		thuchiModel.setGhichu(thuDetailView.getGhichu());
		return thuchiModel.insert(thuchiModel, thuDetailView.getContext());
		
	}
	public ThuChiPresenter(IThuchiView thuchiView)
	{
		this.thuchiView=thuchiView;
	}
	public void getAll()
	{
		IThuchiModel model=new ThuchiModel();
		thuchiView.setListThuchi(model.getAll(thuchiView.getContext()));
	}
	public int delete()
	{
		IThuchiModel thuchiModel=new ThuchiModel();
		return thuchiModel.delete(thuchiView.getContext(), thuchiView.getId());
	}
	public int update()
	{
		IThuchiModel thuchiModel=new ThuchiModel();
		thuchiModel.setKhoanchi(thuDetailView.getKhoanchi());
		thuchiModel.setSotien(thuDetailView.getSotien());
		thuchiModel.setLoaiThuchi(thuDetailView.getLoaiThuChi());
		thuchiModel.setNgaychi(thuDetailView.getNgaychi());
		thuchiModel.setGhichu(thuDetailView.getGhichu());
		thuchiModel.setId(thuDetailView.getId());
		return thuchiModel.update(thuchiModel, thuDetailView.getContext());
	}
	
}
